其基本形式为:
while 判断条件(condition): 执行语句(statements)……
执行语句可以是单个语句或语句块。判断条件可以是任何表达式,任何非零、或非空(null)的值均为True。
当判断条件为假 False 时,循环结束。


举例1:
y=0 while y<10: print(y) y=y+1 结果: 0 1 2 3 4 5 6 7 8 9例题2:
count = 0 while count < 9: print ('The count is:',count) count = count + 1 print("Good bye!")
以上代码执行输出结果:
The count is: 0
The count is: 1
The count is: 2
The count is: 3
The count is: 4
The count is: 5
The count is: 6
The count is: 7
The count is: 8
Good bye!
【Python While循环语句 】相关文章:
python,for循环 2024-04-09
Python 条件语句 2024-03-27
Python 运算符 2024-03-27
Python 变量类型 2024-03-27
第二节:python的input函数用法 2024-03-26
python idle shell 清屏(Python怎么清屏) 2024-10-18
Python While循环语句 2024-04-09
python,for循环 2024-04-09